<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <title>充值</title>
    <link rel="stylesheet" href="../css/ydui.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../iconfont/iconfont.css">
    <script src="../js/ydui.flexible.js"></script>
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
</head>

<body>
    <div class="g-view tupupsPage" id="topupsPage">
        <div class="m-celltitle">充值金额</div>
        <div class="tupups-list">
            <a @click="evconfig(1000,1)" href="javascript:;">
                <h4>1000</h4>
                <span>送10%</span>
                <p>实得1100元</p>
            </a>
            <a @click="evconfig(2000,1)" href="javascript:;">
                <h4>2000</h4>
                <span>送10%</span>
                <p>实得2200元</p>
            </a>
            <a @click="evconfig(3000,1)" href="javascript:;">
                <h4>3000</h4>
                <span>送10%</span>
                <p>实得3300元</p>
            </a>
        </div>
        <div class="m-cell">
            <div class="cell-item">
                <div class="cell-left"><input id="priceinput" class="cell-input" type="number" placeholder="请输入充值金额" /></div>
                <div class="cell-right"><a @click="evconfig(0,2)" href="javascript:;" class="btn btn-primary">充值</a></div>
            </div>
        </div>
        <div></div>
    </div>
    <footer class="m-tabbar tabbar-fixed">
        <a href="../index.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:25px" class="icon iconfont">&#xe617;</i>
            </span>
            <span class="tabbar-txt">询盘商机</span>
        </a>
        <a href="../setup.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:20px" class="icon iconfont">&#xe698;</i>
            </span>
            <span class="tabbar-txt">设置商机</span>
        </a>
        <a href="../release.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:22px" class="icon iconfont">&#xe662;</i>
            </span>
            <span class="tabbar-txt">发布商机</span>
        </a>
        <a href="../vip.html" class="tabbar-item tabbar-active">
            <span class="tabbar-icon">
                <i style="font-size:25px" class="icon iconfont">&#xe67e;</i>
            </span>
            <span class="tabbar-txt">会员中心</span>
        </a>
    </footer>
    <script src="../js/jquery-3.3.1.min.js"></script>
    <script src="../js/ydui.flexible.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../js/ydui.js"></script>
    <script src="../js/nuoxia.js"></script>
    <script>
        window.onload = function () {
            var token = window.localStorage.getItem("token")
            var noticesetupPage = new Vue({
                el: "#topupsPage",
                data: {

                },
                filters: {

                },
                mounted: function () {
                },
                methods: {
                    evconfig: function (p, s) {
                        var _this = this;
                        var appId;
                        var timestamp;
                        var nonceStr;
                        var signature;
                        var urls = window.location.href;
                        $.ajax({//获取微信参数
                            type: "post",
                            url: paraurl + "api/common/getWechatSignPackage?url=" + urls,
                            data: {
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    appId = data.data.appId;
                                    timestamp = data.data.timestamp;
                                    nonceStr = data.data.nonceStr;
                                    signature = data.data.signature;
                                    wx.config({
                                        debug: false,
                                        appId: appId, //公众号的唯一标识
                                        timestamp: timestamp, //生成签名的时间戳
                                        nonceStr: nonceStr, //生成签名的随机串
                                        signature: signature,//签名
                                        jsApiList: ['chooseWXPay']
                                    });
                                    wx.ready(function () {
                                        wx.checkJsApi({
                                            jsApiList: ['chooseWXPay'],
                                            success: function (res) {
                                                if (res.checkResult.getLocation == false) {
                                                    alert('你的微信版本太低，不支持微信JS接口，请升级到最新的微信版本！');
                                                    return;
                                                } else {
                                                    _this.topups(p, s);
                                                }
                                            }
                                        });
                                    });
                                    wx.error(function (res) {
                                        // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
                                        alert(res);
                                    });
                                } else {
                                    return false;
                                }
                            },
                            error: function () {
                                return false;
                            }
                        })
                    },
                    topups: function (e, t) {
                        var _this = this;
                        var price;
                        if (t == 1) {
                            price = e;
                        } else {
                            price = $("#priceinput").val();
                        }
                        $.ajax({
                            type: "post",
                            url: paraurl + "api/user/payAccount?tm=" + tm + "&token=" + token,
                            data: {
                                price: price
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    var total_amount = data.data.total_amount;
                                    var details = data.data.details;
                                    var openid = data.data.openid;
                                    var order_sn = data.data.order_sn;
                                    _this.gitpay(total_amount, details, openid, order_sn)
                                } else {
                                    YDUI.dialog.alert(data.msg);
                                }
                            }
                        })
                    },
                    gitpay: function (total_amount, details, openid, order_sn) {
                        $.ajax({
                            type: "post",
                            url: paraurl + "api/order/getpay?tm=" + tm + "&token=" + token,
                            data: {
                                total_amount: total_amount,
                                details: details,
                                openid: openid,
                                order_sn: order_sn
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    wx.chooseWXPay({
                                        timestamp: data.data.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                                        nonceStr: data.data.nonceStr, // 支付签名随机串，不长于 32 位
                                        package: data.data.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
                                        signType: data.data.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
                                        paySign: data.data.paySign, // 支付签名
                                        success: function (res) {
                                            YDUI.dialog.alert('支付成功!');
                                        }
                                    });
                                } else {
                                    YDUI.dialog.alert(data.msg);
                                }
                            }
                        })
                    }
                }
            })
        }
    </script>
</body>

</html>